﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace hissql
{
    public partial class pat_keshi : Form
    {
        public pat_keshi()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            com2.Items.Clear();
            if(com1.Text  =="外科")
            {
                com2.Items.Add("韩明瑞");
                com2.Items.Add("黄国平");
            }
            if (com1.Text == "妇产科")
            {
                com2.Items.Add("李玲");
                
            }
            if (com1.Text == "心血管内科")
            {
                com2.Items.Add("陈建东");
                com2.Items.Add("郭浩溶");
            }
            if (com1.Text == "口腔科")
            {
                com2.Items.Add("陈永辉");
                com2.Items.Add("林培");
            }
            if (com1.Text == "骨科")
            {
                com2.Items.Add("严康宁");
                com2.Items.Add("柯顺忠");
            }
        }

        private void tb_chaxun_Click(object sender, EventArgs e)
        {
            SqlCommand sqlCommand = new SqlCommand();                                       //声明并实例化SQL命令；
            sqlCommand.Connection = sqlHelper.sqlConnection;                                          //将SQL命令的属性Connection指向SQL连接；
            sqlCommand.CommandText =                                                        //指定SQL命令的命令文本；命令文本由字符串拼接而成；
                "SELECT Brief FROM tb_Doctor"
                + " WHERE Name='" + com2.Text.Trim() + "'";                        //将文本框的文本清除首尾的空格后，拼接至命令文本中；
            sqlHelper.sqlConnection.Open();                                                           //打开SQL连接；
            tb_yisheng.Text = Convert.ToString(sqlCommand.ExecuteScalar());

          SqlCommand sqlCommand1 = new SqlCommand(); 
             sqlCommand1.Connection = sqlHelper.sqlConnection;
            sqlCommand1.CommandText =                                                        //指定SQL命令的命令文本；命令文本由字符串拼接而成；
               "SELECT Brief FROM tb_Department"
               + " WHERE Name='" + this.com1.Text.Trim() + "'";                        //将文本框的文本清除首尾的空格后，拼接至命令文本中；
            tb_keshi.Text = Convert.ToString(sqlCommand1.ExecuteScalar());
            sqlHelper.sqlConnection.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
               string dt = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day .ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();

            string strsql =                                                                        //指定SQL命令的命令文本；
                "INSERT  tb_Invoice (No,DepartmentName,DoctorName,DateTime,Time,PatientNo) VALUES ('"+dt+"','"+com1.Text+"','"+com2.Text+"','"+dt_shijian.Value.Date+"','"+cb_shijian.Text +"', '"+UserHelper.No +"') ";
            SqlCommand comm = new SqlCommand(strsql ,sqlHelper .sqlConnection);
          
                sqlHelper.sqlConnection.Open();

                if (Convert.ToInt32(comm.ExecuteNonQuery()) > 0)
                {
                    
                    MessageBox.Show("预约成功,正在挂号！");
                }
                sqlHelper.sqlConnection.Close();
        }
    }
}
